package com.example.fruitdb.controller;

import com.example.fruitdb.entity.Fruit;
import com.example.fruitdb.service.FruitService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/modifyFruit")
public class modifyServlet extends HttpServlet {
    private FruitService modifyService = new FruitService();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String id = request.getParameter("fid");
        String name = request.getParameter("fname");
        String price = request.getParameter("fprice");
        String count = request.getParameter("fcount");
        String remark = request.getParameter("fremark");
        Fruit fruit = new Fruit();
        fruit.setFid(Integer.parseInt(id));
        fruit.setFname(name);
        fruit.setPrice(Integer.parseInt(price));
        fruit.setFcount(Integer.parseInt(count));
        fruit.setRemark(remark);

        boolean res = modifyService.modifyFruit(fruit);
        PrintWriter out = response.getWriter();
        if(res)
        {
            out.print("success");
        }
        else
        {
            out.print("failed");
        }



    }
}
